﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Forums.ViewModels
{
	using System;
	using System.Collections.Generic;
	using Falcon.Core.Domain;
	using Falcon.Core.Extensions;
	using Falcon.Forums.Domain;
	using Falcon.Forums.Domain.Enums;

	public class ForumPermissionViewModel
	{
		// private fields
		private Forum _forum;
		private UserRole _userRole;

		/// <summary>
		/// Initializes a new instance of the <see cref="ForumPermissionViewModel"/> class.
		/// </summary>
		public ForumPermissionViewModel()
		{
			this.ActionNames = Enum.GetNames(typeof(ForumPermissionActions));
			this.ActionValues = Enum.GetValues(typeof(ForumPermissionActions)).As<int[]>();
			this.PostActionNames = Enum.GetNames(typeof(ForumPostPermissionActions));
			this.PostActionValues = Enum.GetValues(typeof(ForumPostPermissionActions)).As<int[]>();
			this.TopicActionNames = Enum.GetNames(typeof(ForumTopicPermissionActions));
			this.TopicActionValues = Enum.GetValues(typeof(ForumTopicPermissionActions)).As<int[]>();
		}

		/// <summary>
		/// Gets or sets the id.
		/// </summary>
		/// <value>The id.</value>
		public int Id
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the forum id.
		/// </summary>
		/// <value>The forum id.</value>
		public int ForumId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the role id.
		/// </summary>
		/// <value>The role id.</value>
		public int RoleId
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the forum.
		/// </summary>
		/// <value>The forum.</value>
		public Forum Forum
		{
			get
			{
				return _forum;
			}
			set
			{
				_forum = value;

				if (_forum != null)
				{
					this.ForumId = _forum.Id;
				}
			}
		}

		/// <summary>
		/// Gets or sets the role.
		/// </summary>
		/// <value>The role.</value>
		public UserRole Role
		{
			get
			{
				return _userRole;
			}
			set
			{
				_userRole = value;

				if (_forum != null)
				{
					this.RoleId = _userRole.Id;
				}
			}
		}

		/// <summary>
		/// Gets or sets the selected.
		/// </summary>
		/// <value>The selected.</value>
		public Dictionary<string, ForumPermission> Permissions
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the action names.
		/// </summary>
		/// <value>The action names.</value>
		public string[] ActionNames
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the action values.
		/// </summary>
		/// <value>The action values.</value>
		public int[] ActionValues
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the post action names.
		/// </summary>
		/// <value>The post action names.</value>
		public string[] PostActionNames
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the post action values.
		/// </summary>
		/// <value>The post action values.</value>
		public int[] PostActionValues
		{
			get; 
			set;
		}

		/// <summary>
		/// Gets or sets the topic action names.
		/// </summary>
		/// <value>The topic action names.</value>
		public string[] TopicActionNames
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the topic action values.
		/// </summary>
		/// <value>The topic action values.</value>
		public int[] TopicActionValues
		{
			get;
			set;
		}
	}
}